﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public partial class EncryptPassword
    {
        public string PasswordEncrypt(string passwordIn)
        {
            byte[] encode = new byte[passwordIn.Length];
            encode = Encoding.UTF32.GetBytes(passwordIn);
            string passwordOut = string.Empty;
            passwordOut = Convert.ToBase64String(encode);
            return passwordOut;
        }

        private string PassworDecrypt(string passwordIn)
        {
            string decryptpwd = string.Empty;
            UTF8Encoding encodepwd = new UTF8Encoding();
            Decoder Decode = encodepwd.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(passwordIn);
            int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            decryptpwd = new String(decoded_char);
            return decryptpwd;
        }
    }
}
